package com.nowar.frame.proxy;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;

import static org.springframework.util.Assert.notNull;

/**
 * @Author: 谢无殇。
 * @Date : 2023-01-14 21:29
 */
//可通过配置项
//@Configuration
public class HttpProxyScannerConfigurer implements BeanDefinitionRegistryPostProcessor, InitializingBean{
    private String basePackage;

    public void setBasePackage(String basePackage) {
        this.basePackage = basePackage;
    }
    @Override
    public void afterPropertiesSet() throws Exception {
        notNull(this.basePackage, "Property 'basePackage' is required");
    }

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        HttpProxyClassPathBeanDefinitionScanner scanner = new HttpProxyClassPathBeanDefinitionScanner(registry);
        scanner.registerFilters();
        scanner.scan(this.basePackage);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    }
}
